package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.generator.service.MyUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.generator.entity.MyUserEntity;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author rose
     * @email 1942951600@qq.com
 * @date 2021-08-06 21:32:43
 */
@RestController
@RequestMapping("generator/user")
@Api(tags = "分配通知用户" , description = "UserController | 分配通知用户")
public class UserController {
    @Autowired
    private MyUserService userService;

    /**
     * 列表
     */
    @ApiOperation("条件展示")
    @GetMapping("/list")
    @RequiresPermissions("generator:user:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("通过openid查询")
    @GetMapping("/info/{openid}")
    @RequiresPermissions("generator:user:info")
    public R info(@PathVariable("openid") String openid){
		MyUserEntity user = userService.getById(openid);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @PostMapping("/save")
    @RequiresPermissions("generator:user:save")
    public R save(@RequestBody MyUserEntity user){
		userService.save(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PostMapping("/update")
    @RequiresPermissions("generator:user:update")
    public R update(@RequestBody MyUserEntity user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
    @RequiresPermissions("generator:user:delete")
    public R delete(@RequestBody String[] openids){
		userService.removeByIds(Arrays.asList(openids));

        return R.ok();
    }

}
